{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Unique Characters in String\n",
    "\n",
    "## Problem\n",
    "Given a string,determine if it is compreised of all unique characters. For example, the string 'abcde' has all unique characters and should return True. The string 'aabcde' contains duplicate characters and should return false."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Solution\n",
    "We'll show two possible solutions, one using a built-in data structure and a built in function, and another using a built-in data structure but using a look-up method to check if the characters are unique."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "def uni_char(s):\n",
    "    return len(set(s)) == len(s)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "def uni_char2(s):\n",
    "    chars = set()\n",
    "    for let in s:\n",
    "        # Check if in set\n",
    "        if let in chars:\n",
    "            return False\n",
    "        else:\n",
    "            #Add it to the set\n",
    "            chars.add(let)\n",
    "    return True"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Test Your Solution"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "ALL TEST CASES PASSED\n"
     ]
    }
   ],
   "source": [
    "\"\"\"\n",
    "RUN THIS CELL TO TEST YOUR CODE>\n",
    "\"\"\"\n",
    "from nose.tools import assert_equal\n",
    "\n",
    "\n",
    "class TestUnique(object):\n",
    "\n",
    "    def test(self, sol):\n",
    "        assert_equal(sol(''), True)\n",
    "        assert_equal(sol('goo'), False)\n",
    "        assert_equal(sol('abcdefg'), True)\n",
    "        print 'ALL TEST CASES PASSED'\n",
    "        \n",
    "# Run Tests\n",
    "t = TestUnique()\n",
    "t.test(uni_char)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Good Job!"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.2"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 1
}
